# Maintainer: Marcin Sielski <marcin.sielski@motorolasolutions.com>

_realname=openh264
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.3.1
pkgrel=1
pkgdesc="Library for encoding/decoding H264/AVC video streams (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.openh264.org/"
license=("BSD")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-nasm")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/cisco/openh264/archive/v${pkgver}.tar.gz")
sha256sums=('453afa66dacb560bc5fd0468aabee90c483741571bca820a39a1c07f0362dc32')

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "$srcdir/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  if [[ "${MINGW_CHOST}" == "i686-w64-mingw32" ]]; then
    _arch="i686"
  else
    _arch="x86_64"
  fi
  make ARCH=${_arch} AR=ar OS=mingw_nt
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" PREFIX=${MINGW_PREFIX} install
  install -Dm755 h264dec.exe "${pkgdir}${MINGW_PREFIX}"/bin/h264dec.exe
  install -Dm755 h264enc.exe "${pkgdir}${MINGW_PREFIX}"/bin/h264enc.exe

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
